home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Voyeur 1.1.1 / source / Circle WDEF ƒ / circle.c
Encoding:
C/C++ Source or Header  |  1994-10-30  |  4.5 KB  |  176 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        circle.c
  4.  
  5. Purpose:    This is a WDEF that implements a circular window.
  6.  
  7.  
  8. Circle WDEF -=- a circular window
  9. Copyright ©1994, Mark Pilgrim
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program in a file named "GNU General Public License".
  23. If not, write to the Free Software Foundation, 675 Mass Ave,
  24. Cambridge, MA 02139, USA.
  25.  
  26. \**********************************************************************/
  27.  
  28. #define kTitleWidth 2    /* change to your liking */
  29.  
  30. #define hstructure    (*theWindow).strucRgn    /* leave this alone */
  31. #define hcontent    (*theWindow).contRgn    /* leave this alone */
  32.  
  33. // window definition ID = (WDEF resource ID)*16 + window variation code
  34. //
  35. // window variation code masks
  36. #define kShowTitle            0x0001        /* not supported */
  37. #define kNoGrowBox            0x0002        /* never show grow box if kTitleWidth<18 */
  38. #define kTitleBarIsBlack    0x0004        /* if off, title bar is grey */
  39.  
  40. pascal long main(int varCode, WindowPeek theWindow, int message, long param);
  41.  
  42. pascal long main(int varCode, WindowPeek theWindow, int message, long param)
  43. {
  44.     typedef Rect    *RPtr;
  45.     Rect            r, rclose, rgrow;
  46.     int                i, j;
  47.     Point            p;
  48.     GrafPtr            temp;
  49.     PenState        pnState;
  50.     RgnHandle        frame;
  51.     Pattern            pat;
  52.     
  53.     GetPort(&temp);
  54.     SetPort((GrafPtr)theWindow);
  55.     r=(*((GrafPtr)theWindow)).portRect;
  56.     i=r.right-r.left;
  57.     j=r.bottom-r.top;
  58.     if (i>j) i=j;
  59.     r.left=r.top=0;
  60.     LocalToGlobal(&r);
  61.     SetPort(temp);
  62.     r.bottom=r.top+i;
  63.     r.right=r.left+i;
  64.     
  65.     j=(i/2)+((i/2)*10)/14;
  66.     rgrow.right=r.left+j;
  67.     rgrow.bottom=r.top+j;
  68.     rgrow.left=rgrow.right-12;
  69.     rgrow.top=rgrow.bottom-12;
  70.     
  71.     SetRect(&rclose, r.left+3, r.top+(i/2)-6, r.left+14, r.top+(i/2)+5);
  72.     
  73.     switch (message)
  74.     {
  75.         case wDraw:
  76.             if (!((*theWindow).visible)) break;
  77.             if (param==0L)
  78.             {
  79.                 pat[0]=pat[2]=pat[4]=pat[6]=
  80.                     (((*theWindow).hilited) && (varCode&kTitleBarIsBlack)) ? 0xFF :
  81.                     ((*theWindow).hilited) ? 0x55 : 0x00;
  82.                 pat[1]=pat[3]=pat[5]=pat[7]=
  83.                     (((*theWindow).hilited) && (varCode&kTitleBarIsBlack)) ? 0xFF :
  84.                     ((*theWindow).hilited) ? 0xAA : 0x00;
  85.                 
  86.                 FrameOval(&r);
  87.                 InsetRect(&r, 1, 1);
  88.                 frame=NewRgn();
  89.                 OpenRgn();
  90.                 FrameOval(&r);
  91.                 InsetRect(&r, kTitleWidth-2, kTitleWidth-2);
  92.                 FrameOval(&r);
  93.                 CloseRgn(frame);
  94.                 FillRgn(frame, &pat);
  95.                 DisposeRgn(frame);
  96.                 FrameOval(&r);
  97.                 
  98.                 if (((*theWindow).hilited) && ((*theWindow).goAwayFlag))
  99.                 {
  100.                     EraseRect(&rclose);
  101.                     FrameRect(&rclose);
  102.                 }
  103.                 
  104.                 if (((*theWindow).hilited) && ((varCode&kNoGrowBox)==0))
  105.                 {
  106.                     EraseRect(&rgrow);
  107.                     FrameRect(&rgrow);
  108.                 }
  109.                 
  110. //                if (varCode&0x0001)
  111. //                {
  112. //                    would draw title in here if we supported that
  113. //                }
  114.             }
  115.             else if (param==4L)
  116.             {
  117.                 GetPenState(&pnState);
  118.                 PenMode(patXor);
  119.                 MoveTo(rclose.left+2, rclose.top+2);
  120.                 Line(6, 6);
  121.                 MoveTo(rclose.left+2, rclose.bottom-3);
  122.                 Line(6,-6);
  123.                 MoveTo(rclose.left+1, rclose.top+5);
  124.                 Line(8, 0);
  125.                 MoveTo(rclose.left+5, rclose.top+1);
  126.                 Line(0, 8);
  127.                 InsetRect(&rclose, 4, 4);
  128.                 EraseRect(&rclose);
  129.                 SetPenState(&pnState);
  130.             }
  131.             break;
  132.         case wHit:
  133.             p.v=HiWord(param);
  134.             p.h=LoWord(param);
  135.             if (PtInRgn(p, hcontent)) return 1L;
  136.             else if (((*theWindow).hilited) && ((*theWindow).goAwayFlag) &&
  137.                     (PtInRect(p, &rclose))) return 4L;
  138.             else if (((*theWindow).hilited) && ((varCode&kNoGrowBox)==0) &&
  139.                     (PtInRect(p, &rgrow))) return 3L;
  140.             else if (PtInRgn(p, hstructure)) return 2L;
  141.             break;
  142.         case wCalcRgns:
  143.             SetEmptyRgn(hstructure);
  144.             OpenRgn();
  145.             FrameOval(&r);
  146.             CloseRgn(hstructure);
  147. //            if (varCode&kShowTitle)
  148. //            {
  149. //                would define title region in here if we supported that
  150. //            }
  151.             InsetRect(&r, kTitleWidth, kTitleWidth);
  152.             SetEmptyRgn(hcontent);
  153.             OpenRgn();
  154.             FrameOval(&r);
  155.             CloseRgn(hcontent);
  156.             break;
  157.         case wNew:
  158.             break;
  159.         case wDispose:
  160.             break;
  161.         case wGrow:
  162.             r=*(RPtr)param;
  163.             i=r.right-r.left;
  164.             j=r.bottom-r.top;
  165.             if (i>j) i=j;
  166.             r.right=r.left+i;
  167.             r.bottom=r.top+i;
  168.             FrameOval(&r);
  169.             break;
  170.         case wDrawGIcon:
  171.             break;
  172.     }
  173.     
  174.     return 0L;
  175. }
  176.